﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Web.UI.WebControls;
using SiteUtils;
using System.Web.UI;
using System.Reflection;
using System.ComponentModel;
using System.Configuration;
using System.Collections;
using System.Web.Security;
using System.Text.RegularExpressions;
/// <summary>
/// A JavaScript alert
/// </summary>
/// 
public static class CheckValidateUtility
{
    public static bool IsNumber(string pValue)
    {
        foreach (Char c in pValue)
        {
            if (!Char.IsDigit(c))
                return false;
        }
        return true;
    }

    public static bool IsValidEmail(string email)
    {
        string pattern = @"^[-a-zA-Z0-9][-.a-zA-Z0-9]*@[-.a-zA-Z0-9]+(\.[-.a-zA-Z0-9]+)*\.
 (com|edu|info|gov|int|mil|net|org|biz|name|museum|coop|aero|pro|tv|[a-zA-Z]{2})$";

        Regex check = new Regex(pattern, RegexOptions.IgnorePatternWhitespace);

        bool valid = false;
        if (string.IsNullOrEmpty(email))
        {
            valid = false;
        }
        else
        {
            valid = check.IsMatch(email);
        }
        return valid;
    }
}
public static class Alert
{

    /// <summary>
    /// Shows a client-side JavaScript alert in the browser.
    /// </summary>
    /// <param name="message">The message to appear in the alert.</param>
    public static void Show(string message)
    {
        // Cleans the message to allow single quotation marks
        string cleanMessage = message.Replace("'", "\\'");
        string script = "<script type=\"text/javascript\">alert('" + cleanMessage + "');</script>";

        // Gets the executing web page
        Page page = HttpContext.Current.CurrentHandler as Page;

        // Checks if the handler is a Page and that the script isn't allready on the Page
        if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("alert"))
        {
            page.ClientScript.RegisterClientScriptBlock(typeof(Alert), "alert", script);
        }
    }
    public static void ClodePopup( )
    {
        // Cleans the message to allow single quotation marks
     //   string cleanMessage = message.Replace("'", "\\'");
        string script = "<script type=\"text/javascript\">  window.parent.closeColorBoxNotConfirm();</script>";

        // Gets the executing web page
        Page page = HttpContext.Current.CurrentHandler as Page;

        // Checks if the handler is a Page and that the script isn't allready on the Page
        if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("ClodePopup"))
        {
            page.ClientScript.RegisterClientScriptBlock(typeof(Alert), "ClodePopup", script);
        }
    }
    public static void ReloadPage()
    {
        // Cleans the message to allow single quotation marks
        //   string cleanMessage = message.Replace("'", "\\'");
        string script = "<script type=\"text/javascript\"> window.parent.location.reload(true);</script>";

        // Gets the executing web page
        Page page = HttpContext.Current.CurrentHandler as Page;

        // Checks if the handler is a Page and that the script isn't allready on the Page
        if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("ReloadPage"))
        {
            page.ClientScript.RegisterClientScriptBlock(typeof(Alert), "ReloadPage", script);
        }
    }
}
public class utility
{


    // remove "this" if not on C# 3.0 / .NET 3.5
    // public static DataTable ToDataTable<T>(this List<T> data)
    public DataTable ToDataTable<T>(List<T> data)
    {
        PropertyDescriptorCollection props =
            TypeDescriptor.GetProperties(typeof(T));
        DataTable table = new DataTable();
        for (int i = 0; i < props.Count; i++)
        {
            PropertyDescriptor prop = props[i];
            table.Columns.Add(prop.Name, prop.PropertyType);
        }
        object[] values = new object[props.Count];
        foreach (T item in data)
        {
            for (int i = 0; i < values.Length; i++)
            {
                values[i] = props[i].GetValue(item);
            }
            table.Rows.Add(values);
        }
        return table;
    }

    public void BindingDataToGridNoFooterNoPaging(DataGrid grd, DataTable dtSource)
    {
        grd.DataSource = dtSource;
        try
        {
            grd.DataBind();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    public void BindingDataToGridNoFooterNoPaging(DataGrid grd, DataSet dtSource)
    {
        grd.DataSource = dtSource;
        try
        {
            grd.DataBind();
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

    public string InGT(double d)
    {
        if (d == 0)
            return "";
        else
            return d.ToString("#.###");
    }
}